﻿#ifndef __SS_MSG_ENGINE_H__
#define __SS_MSG_ENGINE_H__
#include "../ssBaseDefine.h"
#include "../message/ssMsgIdDef.h"
#include "ssThreadBase.h"
#include "./threadLock/ssThreadLock.h"
#include "../time/ssTimer.h"
#include "../container/ssList.h"


namespace StarSeeker
{

class ssMsgEngine : public ssThreadBase
{
public:
	ssMsgEngine();
	virtual ~ssMsgEngine();
	//向县城传递消息
	bool PostMsg(ssMsg_s &m);
	bool PostMsg(u32 msgID, u32 subID, ulint param1, ulint param2, ulint param3);
	//停止线程
	void ExitThread();
	//最大缓存数
	void SetMaxMsgCount(u32 ct);
	//当前任务数,强转成32位整数才是消息列表的数量
	u64 GetMsgCount();
protected:
	virtual void ThreadMemberFunc();
	//消息处理
	virtual void HandleMessage(ssMsg_s &m) { return; }
	//线程启动时调用
	virtual void OnThreadRun() { return; }

protected:
	ssThreadLock			m_mutex;		//互斥量
	u32						m_maxMsgCount;	//最大缓存数,默认100000
	ssList<ssMsg_s>			m_msgList;		//消息链表
	ssList<ssMsg_s>			m_tempList;
#ifdef SS_THREAD_FRAME_TIMER
	ssFrameTimer			m_timer;
#endif
};

}
#endif
